package com.lms.logistics_management_system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lms.logistics_management_system.entity.Doctor;
import com.lms.logistics_management_system.mapper.dto.ItemListDto;
import com.lms.logistics_management_system.entity.Reservation;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;


@Mapper
public interface ReservationMapper extends BaseMapper<Reservation> {

    @Select("SELECT distinct reservation_id, reservation_appointment_time, reservation_buy_price, reservation_buy_time, user_openid, reservation_name, reservation_id_number, reservation_phone_number, reservation_sex, reservation_is_married\n" +
            "FROM reservation r\n" +
            "JOIN reservation_item ri ON r.reservation_id=ri.reservation_id\n" +
            "WHERE opend_id=#{openId} AND NOT EXISTS\n "+
            "SELECT * from ri where reservation_item_result_comeout=ABS(1-#{finished})\n"+
            "GROUP BY reservation_id\n" +
            "ORDER BY item_id DESC;") //没完成：不存在一个是不是0的
    List<Reservation> getClassifiedReservationsByOpenid(String openId,Integer finished);


    @Select("select * from reservation where user_openid=#{openId}")
    Doctor getByOpenId(String openId);

    //    @Select("select * from reservation left inner join department")
    @Select("select * from reservation left inner join department")
    boolean showAllResinfo();

    // ----------------以下为检中-----------
    @Select("SELECT item.department_id,department_name,item_id,item_name,item_price FROM item,department\n" +
            "WHERE item.department_id=department.department_id")
    List<ItemListDto> getAllItemList();
    //<!--    添加项目到订单1、更改订单价格2、在订单和item的对应表中插入一行-->
    @Insert("INSERT reservation_item(reservation_id,item_id,reservation_item_result_comeout) VALUES(#{reservationId},#{itemId},0)")
    boolean addItemToReservation(Integer reservationId, Integer itemId);

    @Select("select reservation_name from reservation where reservation_id=#{reservationId}")
    String getReservationName(Integer reservationId);


}
//
//@Select("SELECT distinct reservation_id, reservation_appointment_time, reservation_buy_price, reservation_buy_time, user_openid, reservation_name, reservation_id_number, reservation_phone_number, reservation_sex, reservation_is_married\n" +
//        "FROM reservation r\n" +
//        "JOIN reservation_item ri ON r.reservation_id=ri.reservation_id\n" +
//        "WHERE opend_id=#{openId} AND reservation_item_result_comeout=#{finished}\n" +
//        "GROUP BY reservation_id\n" +
//        "ORDER BY item_id DESC;")
